package com.he.controller;

import com.he.config.KafkaConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
public class KafkaController {

    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;

    @GetMapping("/send")
    public String send() {
        for (int i = 0; i < 10; i++) {
            kafkaTemplate.send(KafkaConfig.TOPIC_NAME, "Message #" + i);
        }
        return "Sent 10 messages";
    }
}
